package popup

import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.widget.Button
import android.widget.PopupWindow
import app.AppContext
import com.hontech.kdxclient.R
import ext.log

class NetworkFaultWindow : View.OnLongClickListener {

    companion object {

        var isShow = false
        val Instance: NetworkFaultWindow by lazy { NetworkFaultWindow() }
    }

    private val mView = LayoutInflater.from(AppContext).inflate(R.layout.popup_network, null)
    private val mWindow = PopupWindow(mView, 500, 500, true)
    private val mButton = mView.findViewById<Button>(R.id.id_network_quit_button)

    init {
        mButton.setOnLongClickListener(this)
    }

    override fun onLongClick(p0: View?): Boolean {
        dismiss()
        return true
    }

    fun dismiss() {
        log("关闭网络状态信号Window:$isShow")
        if (!isShow) {
            return
        }
        isShow = false
        mWindow.dismiss()
    }

    fun show(parent: View) {
        log("开始网络状态Window:$isShow")
        if (isShow) {
            return
        }
        mWindow.showAtLocation(parent, Gravity.CENTER, 0, 0)
        isShow =  true
    }
}
